<?php

use Biz\cache\wiki\WikiBasicCounter;
use Biz\model\FineGoodsBrokeNews\FineGoodsBrokeNewsFavouriteLogModel;
use Biz\model\FineGoodsBrokeNews\FineGoodsBrokeNewsModel;
use Biz\service\FineGoodsBrokeNews\FineGoodsBrokeNewsService;
use Biz\service\wiki\Wiki;
use Biz\service\wiki\WikiBasic;
use Doraemon\cache\UserCounter;
use Doraemon\pockets\constInterface\FormatScene;
use Doraemon\service\Format\Note\HandleNote;
use Doraemon\service\Photos;
use Doraemon\service\User as mUser;
use Doraemon\service\ForbiddenWord\ForbiddenSceneWord;
use Doraemon\model\ForbiddenWord\ForbiddenSceneWord as ForbiddenSceneWordModel;


/**
 * @deprecated
 */
class TestAction extends ActionPlugin
{
    public function main()
    {
        $rs = mUser::getUsers([10001]);
        return $this->setSuccess($rs);

    }
    public function main1()
    {
        $note = [
            // 2010-11
            '000lznc00000ighj','000m07s00000ws92','000m0ib00000rxg7'
            // 2010-10
//            ,'000lq2a000005zzm'
//            ,'000d7x400000xx6f'
//            ,'000nbp400000nbms'
//            ,'000d7z300001ajlq'
//            ,'00001gz05001ajlq'
//            ,'000nbp400000nbms'
//            ,'000d7zg00001ajlq'
//            ,'000d80w00001ajlq'
//            ,'000da8u00001ajlq'
//            ,'000bcp0000006x98'
//            ,'000d7x600000xx6f'
//            ,'000d7x400000xx6f'
//            ,'0000d0k000000kmn'
//            ,'0000d0n000000kmn'
//            ,'0000d0n000000kmn'
//            ,'0000d0n000000kmn'
//            ,'00006gz0000009zd'
//            ,'0000ejb000000mcn'
//            ,'0000bq5000000igf'
        ];
        $wiki = ['104'
            ,'105'
            ,'106'
            ,'107'
//            ,'108'
//            ,'109'
//            ,'110'
//            ,'111'
//            ,'112'
//            ,'113'
//            ,'114'
//            ,'115'
//            ,'116'
//            ,'117'
//            ,'118'
//            ,'119'
//            ,'120'
//            ,'121'
//            ,'122'
//            ,'123'
        ];
        $user = [
            '10011'
//            ,'10001'
//            ,'10002'
//            ,'10003'
//            ,'10004'
//            ,'10005'
//            ,'10006'
//            ,'10007'
//            ,'10008'
//            ,'10009'
//            ,'10010'
        ];
        // 每个人发几个note
        $notePublic = 5;
        // 每个人发几次wiki
        $wikiPublish = 5;
        // 每次几个wiki
        $wikiItemPublish = 6;
        $data = [];
        foreach($user as $k => $v){
            $noteCount = random_int(1,$notePublic);
            $wikiCount = random_int(1,$wikiPublish);
            for($i = 0;$i < $noteCount;$i++){
                $tmp = ['uid' => $v];
                shuffle($note);
                $tmp['note'] = array_slice($note,0,1)[0];
                $tmp['wiki'] = [];
                $data[] = $tmp;
            }
            for($i = 0;$i < $wikiCount;$i++){
                $wikiItemCount = random_int(1,$wikiItemPublish);
                $tmp = ['uid' => $v];
                shuffle($wiki);
                $tmp['wiki'] = array_slice($wiki,0,$wikiItemCount);
                $tmp['note'] = "";
                $data[] = $tmp;
            }
        }
        shuffle($data);
        foreach ($data as $datum) {
            if(!empty($datum['wiki'])){
                $wikiJson = [];
                foreach ($datum['wiki'] as $item) {
                    $wikiJson[] = [
                        'basic_id' => $item,
                        'comment' => $this->random_string()
                    ];
                    FineGoodsBrokeNewsService::saveData([
                        'uid' => $datum['uid'],
                        'data' => $wikiJson
                    ]);
                }
            }
            if(!empty($datum['note'])){
                FineGoodsBrokeNewsService::addNoteLog([
                    'uid' => $datum['uid'],
                    'id' => $datum['note']
                ]);
            }
        }
        return $this->setSuccess($data);
    }

    private function microtime()
    {
        $time = explode (" ", microtime () );
        $time = $time [1] . ($time [0] * 1000);
        $time2 = explode ( ".", $time );
        $time = $time2 [0];
        return $time;
    }

    private function random_string()
    {
        $str = md5($this->microtime());
        return substr($str,0,20);
    }
}